import { request } from "../request";

// 参数接口
export interface SubmitSingleAnswerParams {
  studentId?: number;
  examId?: number;
  questionId?: number;
  answer?: string;
}

// 返回数据接口
export interface SubmitSingleAnswerRes {
  code: number;
  message: string;
  data: Record<string, unknown>;
  timestamp: Record<string, unknown>;
}

// 参数接口
export interface SubmitBatchAnswersParams {
  studentId?: number;
  examId?: number;
  answers?: {
    questionId?: number;
    answer?: string;
  }[];
}

// 返回数据接口
export interface SubmitBatchAnswersRes {
  code: number;
  message: string;
  data: Record<string, unknown>;
  timestamp: Record<string, unknown>;
}

const token = localStorage.getItem("token");

// 提交单个答案
const submitSingleAnswerAPI = async (params: SubmitSingleAnswerParams): Promise<SubmitSingleAnswerRes> => {
  const token = localStorage.getItem("token");
  return request("/api/student-answers/submit-single", {
    method: "post",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${token}`,
    },
    data: JSON.stringify(params),
  });
};

// 批量提交答案
const submitBatchAnswersAPI = async (params: SubmitBatchAnswersParams): Promise<SubmitBatchAnswersRes> => {
  const token = localStorage.getItem("token");
  return request("/api/student-answers/submit-batch", {
    method: "post",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${token}`,
    },
    data: JSON.stringify(params),
  });
};

export { submitSingleAnswerAPI, submitBatchAnswersAPI };
